from leetcode_test import *


class Solution:
    def levelOrder(self, root: TreeNode) -> List[List[int]]:
        levels = []

        if not root:
            return
        def helper(node: TreeNode, level: int):
            print(level)
            if len(levels) == level:
                levels.append([])
            
            levels[level].append(node.val)
            if node.left:
                helper(node.left, level + 1)
            if node.right:
                helper(node.right, level + 1)
                
        helper(root, 0)
        return levels


def test():
    t = TreeNode.create([3, 9, 20, None, None, 15, 7])
    assert Solution().levelOrder(t) == [[3], [9, 20], [15, 7]]


def test2():
    t = TreeNode.create([5, 4, 7, 3, None, 2, None, -1, None, 9])
    assert Solution().levelOrder(t) == [[5], [4, 7], [3, 2], [-1, 9]]


if __name__ == "__main__":
    t = TreeNode.create([5])
    print(Solution().levelOrder(t))
